package com.diyunapp.xilinapp.adapters;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.diyunapp.xilinapp.R;
import com.diyunapp.xilinapp.bean.CollectShopBean;
import com.diyunapp.xilinapp.bean.DeleteBean;
import com.squareup.picasso.Picasso;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2016/7/17.
 */
public class CollectShopAdapter extends BaseAdapter {
    private List<CollectShopBean.DateBean.StoreBean> info = new ArrayList<CollectShopBean.DateBean.StoreBean>();
    private Context context;
//    private LayoutInflater inflater;

    //        private LendNoDebtFragment lendNoDebtFragment;
    public CollectShopAdapter(Context context) {
        super();
        this.context = context;
    }

    public void setList(List<CollectShopBean.DateBean.StoreBean> list) {
        this.info = list;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return null == info ? 0 : info.size();
    }

    @Override
    public Object getItem(int position) {
        return null == info ? null : info.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    private ViewHolder viewHolder;

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        if (null == convertView) {
            LayoutInflater layoutInflater = LayoutInflater.from(context);
            convertView = layoutInflater.inflate(R.layout.item_fragment_collectshop, null);

            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        CollectShopBean.DateBean.StoreBean bean = info.get(position);
        DeleteBean deleteBean = null;
        boolean state = false;

//        state=deleteBean.isDeleteState();
//        Log.i("xiaogalade", "params=" + String.valueOf(state));
//        if (String.valueOf(state) == "false") {
//            viewHolder.buycarDeleteallTv.setVisibility(View.GONE);
//        } else if (String.valueOf(state) == "true") {
//            viewHolder.buycarDeleteallTv.setVisibility(View.VISIBLE);
//        }
        viewHolder.introduceShop.setText(bean.getStore_name());
//            Toast.makeText(getActivity(), bean.getStore_name(), Toast.LENGTH_SHORT).show();
        viewHolder.num.setText(bean.getStore_phone());
        viewHolder.saleNum.setText(bean.getStore_vrcode_prefix());
        String image = bean.getStore_slide_url();
        Picasso.with(context)
                .load(image)
                .resize(200, 200)
                .centerCrop()
                .placeholder(R.drawable.launcher_icon)
                .error(R.drawable.launcher_icon)
                .into(viewHolder.goodsImage);

        return convertView;
    }


    static class ViewHolder {
        @Bind(R.id.goods_image)
        ImageView goodsImage;
        @Bind(R.id.introduce_shop)
        TextView introduceShop;
        @Bind(R.id.phone)
        TextView phone;
        @Bind(R.id.num)
        TextView num;
        @Bind(R.id.yishou)
        TextView yishou;
        @Bind(R.id.sale_num)
        TextView saleNum;
        @Bind(R.id.buycar_deleteall_tv)
        TextView buycarDeleteallTv;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }

}



